﻿using Microsoft.AspNetCore.Mvc;
using RobosimAPI.Class;

namespace RobosimAPI.Controllers
{
	[Route("back/Api2/Client/checkUserLoginToken")]
	public class CheckUserLoginTokenController : ControllerBase
	{
		[HttpPost]
		public IActionResult CheckUserLoginToken([FromForm] CheckUserModel model)
		{
			if (!model.IsValid())
			{
				return Ok(new ErrorResponse() { errmsg = "_MISS_TOKEN_", status=-1});
			}
			Account account = new Account(model.user_id);
			if (account.token!= model.token)
			{
				return Ok(new ErrorResponse() { errmsg = "Account has been logged in repeatedly", status=-1});
			}
			return Ok(new ErrorResponse() { status=1,errmsg=""});
		}
		public class CheckUserModel
		{
			public int user_id { get; set; }
			public int jmd_id { get; set; }
			public string? token { get; set; }
			public bool IsValid()
			{
				return user_id > 0 && jmd_id > 0 && token!= null;
			}
		}
	}
}
